package ink.ykb.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WorkQueueRabbitConfig {

	/** 测试队列：test */
	public final static String TEST_QUEUE = "test";
	
	public final static String DEFULT_QUEUE = "defult";

	public final static String TEST_ONE_QUEUE = "test.one";

	public final static String TEST_EXCHANGE = "test";

	public static final String WORK_TEST_QUEUE = "work_test";

	public static final String WORK_TEST_EXCHANGE = "work_test";

	@Bean
    public Queue defultQueue() {
        return new Queue(DEFULT_QUEUE);
    }
	
	@Bean
	public Queue testQueue() {
		return new Queue(TEST_QUEUE);
	}

	@Bean
	public Queue testOneQueue() {
		return new Queue(TEST_ONE_QUEUE);
	}

	@Bean
	public Exchange testExchange() {
		return ExchangeBuilder.directExchange(TEST_EXCHANGE).durable(true).build();
	}

	@Bean
	public Binding bindingExchange(Queue testQueue, DirectExchange testExchange) {
		return BindingBuilder.bind(testQueue).to(testExchange).with(TEST_QUEUE);
	}

	@Bean
	public Binding bindingOneExchange(Queue testOneQueue, DirectExchange testExchange) {
		return BindingBuilder.bind(testOneQueue).to(testExchange).with(TEST_QUEUE);
	}

	// 工作队列
	@Bean
	public Queue workQueue() {
		return new Queue(WORK_TEST_QUEUE, true);
	}

	// 工作交换机
	@Bean
	public Exchange workExchange() {
		return ExchangeBuilder.directExchange(WORK_TEST_EXCHANGE).durable(true).build();
	}

	// 绑定工作队列到工作交换机上
	@Bean
	public Binding bindingWork(Queue workQueue, Exchange workExchange) {
		return BindingBuilder.bind(workQueue).to(workExchange).with(WORK_TEST_QUEUE).noargs();
	}

}
